package com.yuntsg.nnsfcp.service;

import com.yuntsg.nnsfcp.entity.ChaShou;
import com.yuntsg.nnsfcp.front.mapper.TemplateMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Service
public class TemplateService {

    @Resource
    TemplateMapper templateMapper;


    //根据模板类型返回需要的下载的文本
    public String backContent(int id) {

        /*
         * 根据模板的不同拼接不同的参数
         * 1是查新报告的参数
         * 2是查新合同
         * 3是查收
         * 4是查引
         * */
        //假定是1
        String content2 = templateMapper.selectById(id).getTemplate();

        if (id == 1) {
            String sn = ""; //报告合同编号
            String proName = ""; //项目名称
            String linkName = ""; //委托人
            String data = ""; //委托日期
            String comDate = ""; // 完成日期
            String proName1 = "";   //查新项目中文名称
            String proNameEn = ""; //查新项目英文名称
            String purpose = ""; //查新目的
            String purposePoint = ""; //查新点
            String scope = ""; //文献范围
            String searchKey = ""; //检索词
            sn = "123";
            proName = "测试项目名称";
            linkName = "联系人姓名";
            data = "2019-6-1";
            comDate = "2019-6-15";
            proName1 = proName;
            proNameEn = "english test";
            purpose = "查新目的测试";
            purposePoint = "查引要点";
            scope = "文献范围";
            content2 = content2.replace("{$sn}", sn);
            content2 = content2.replace("{$cn_name}", proName);
            content2 = content2.replace("{$en_name}", proNameEn);
            content2 = content2.replace("{$linkname}", linkName);
            content2 = content2.replace("{$date}", data);
            content2 = content2.replace("{$complete_date}", comDate);
            content2 = content2.replace("{en_name}", proNameEn);
            content2 = content2.replace("{$main_point}", purposePoint);
            content2 = content2.replace("{$scope}", scope);
            content2 = content2.replace("{$search_term}", searchKey);
        }
        if (id == 3) {

            String sn = ""; //报告合同编号
            String cnName = ""; //被检作者 中文
            String enName = ""; //被检作者 英文
            String thesisNum = ""; //供待检索论文篇数
            String timeClaim = ""; // 论文年限
            List resultList = new ArrayList();   //检索结果
            String searchUser = ""; //检索人
            String checkUser = ""; //审核人
            String time = ""; //检索时间
            String thesisInclude_list = ""; //检索词
            sn = "123";
            List<ChaShou> ls = new ArrayList();
            /*
             * 测试数据
             * */
            ChaShou chaShou = new ChaShou("标题1", "葛成瑞", "2015年", "期刊", "是", "4.2", "1", "", "Q1");
            ChaShou chaShou1 = new ChaShou("标题2", "刘家兴", "2096年", "期刊", "是", "4.2", "1", "", "Q1");
            ChaShou chaShou2 = new ChaShou("标题3", "周士伟", "2016年", "期刊", "是", "4.2", "1", "", "Q1");
            ChaShou chaShou3 = new ChaShou("标题4", "李倩倩", "2016年", "期刊", "是", "4.2", "1", "", "Q1");
            ls.add(chaShou);
            ls.add(chaShou1);
            ls.add(chaShou2);
            ls.add(chaShou3);
//            ls.forEach(str ->{
//                System.out.println();str.getIsCheck();
//
//            });
            StringBuffer sb = new StringBuffer();

//             title; //文章提名
//             applyOrder; //申请人排名
//             njqy; //出版物的年卷期刊
//             titleType; //文章类型
//             isCheck; //收录情况 是 后
//             ImpactFactor; //影响因子
//             CitedNum; //被引次数
//             subjectType; //学科类别 暂时没用
//             Partition; //分区
            int s = 1;
            for (int i = 0; i < ls.size(); i++) {
                ChaShou c = ls.get(i);
                String result = "<tr align=\"center\">\n" +
                        "            <td valign=\"middle\" style=\"word-break: break-all;\">\n" + s +
                        "                \n" +
                        "            </td>\n" +
                        "            <td width=\"205\" valign=\"top\" style=\"word-break: break-all;\">" + c.getTitle() + "</td>\n" +
                        "            <td width=\"205\" valign=\"top\" style=\"word-break: break-all;\">" + c.getApplyOrder() + "</td>\n" +
                        "            <td width=\"205\" valign=\"top\" style=\"word-break: break-all;\">" + c.getNjqy() + "</td>\n" +
                        "            <td width=\"205\" valign=\"top\" style=\"word-break: break-all;\">" + c.getTitleType() + "</td>\n" +
                        "            <td width=\"205\" valign=\"top\" style=\"word-break: break-all;\">" + c.getIsCheck() + "</td>\n" +
                        "            <td width=\"205\" valign=\"top\" style=\"word-break: break-all;\">" + c.getImpactFactor() + "</td>\n" +
                        "            <td width=\"205\" valign=\"top\" style=\"word-break: break-all;\">" + c.getCitedNum() + "</td>\n" +
                        "            <td width=\"205\" valign=\"top\" style=\"word-break: break-all;\">" + c.getSubjectType() + "</td>\n" +
                        "            <td width=\"205\" valign=\"top\" style=\"word-break: break-all;\">" + c.getPartition() + "</td>\n" +
                        "        </tr>";

                sb.append(result);
                s++;
            }
            content2 = content2.replace("resultlist", sb);
            /*
             * 采用jsoup进行网页的添加
             * */

//            proName = "测试项目名称";
//            linkName = "联系人姓名";
//            data = "2019-6-1";
//            comDate = "2019-6-15";
//            proName1 = proName;
//            proNameEn = "english test";
//            purpose = "查新目的测试";
//            purposePoint = "查引要点";
//            scope = "文献范围";
//            content2 = content2.replace("{$sn}",sn);
//            content2 = content2.replace("{$cn_name}",proName);
//            content2 = content2.replace("{$en_name}",proNameEn);
//            content2 = content2.replace("{$linkname}",linkName);
//            content2 = content2.replace("{$date}",data);
//            content2 = content2.replace("{$complete_date}",comDate);
//            content2 = content2.replace("{en_name}",proNameEn);
//            content2 = content2.replace("{$main_point}",purposePoint);
//            content2 = content2.replace("{$scope}",scope);
//            content2 = content2.replace("{$search_term}",searchKey);
        }
        return content2;
    }

}
